package com.huawei.secure.android.common.util;

import android.text.TextUtils;
import android.util.Log;
import com.tencent.mm.opensdk.modelmsg.WXMediaMessage;
import java.util.regex.Pattern;

public class LogsUtil {
    private static final Pattern j = Pattern.compile("[0-9]*[a-z|A-Z]*[一-龥]*");
    private static final char k = '*';
    private static final int l = 2;

    private static String a(String str, boolean z) {
        StringBuilder stringBuilder = new StringBuilder(WXMediaMessage.TITLE_LENGTH_LIMIT);
        if (!TextUtils.isEmpty(str)) {
            if (z) {
                stringBuilder.append(a(str));
            } else {
                stringBuilder.append(str);
            }
        }
        return stringBuilder.toString();
    }

    private static String a(String str, String str2) {
        StringBuilder stringBuilder = new StringBuilder(WXMediaMessage.TITLE_LENGTH_LIMIT);
        if (!TextUtils.isEmpty(str)) {
            stringBuilder.append(str);
        }
        if (!TextUtils.isEmpty(str2)) {
            stringBuilder.append(a(str2));
        }
        return stringBuilder.toString();
    }

    public static void d(String str, String str2, boolean z) {
        if (!TextUtils.isEmpty(str2)) {
            Log.d(str, a(str2, z));
        }
    }

    public static void d(String str, String str2, String str3) {
        if (!TextUtils.isEmpty(str2) || !TextUtils.isEmpty(str3)) {
            Log.d(str, a(str2, str3));
        }
    }

    public static void d(String str, String str2, String str3, Throwable th) {
        if (!TextUtils.isEmpty(str2) || !TextUtils.isEmpty(str3)) {
            Log.d(str, a(str2, str3), a(th));
        }
    }

    public static void d(String str, String str2) {
        if (!TextUtils.isEmpty(str2)) {
            Log.d(str, a(str2, false));
        }
    }

    public static void d(String str, String str2, Throwable th, boolean z) {
        if (!TextUtils.isEmpty(str2)) {
            Log.d(str, a(str2, z), a(th));
        }
    }

    public static void d(String str, String str2, Throwable th) {
        if (!TextUtils.isEmpty(str2) || th != null) {
            Log.d(str, a(str2, false), a(th));
        }
    }

    public static void i(String str, String str2, boolean z) {
        if (!TextUtils.isEmpty(str2)) {
            Log.i(str, a(str2, z));
        }
    }

    public static void i(String str, String str2, String str3) {
        if (!TextUtils.isEmpty(str2) || !TextUtils.isEmpty(str3)) {
            Log.i(str, a(str2, str3));
        }
    }

    public static void i(String str, String str2, String str3, Throwable th) {
        if (!TextUtils.isEmpty(str2) || !TextUtils.isEmpty(str3)) {
            Log.i(str, a(str2, str3), a(th));
        }
    }

    public static void i(String str, String str2) {
        if (!TextUtils.isEmpty(str2)) {
            Log.i(str, a(str2, false));
        }
    }

    public static void i(String str, String str2, Throwable th, boolean z) {
        if (!TextUtils.isEmpty(str2) || th != null) {
            Log.i(str, a(str2, z), a(th));
        }
    }

    public static void i(String str, String str2, Throwable th) {
        if (!TextUtils.isEmpty(str2) || th != null) {
            Log.i(str, a(str2, false), a(th));
        }
    }

    public static void w(String str, String str2, boolean z) {
        if (!TextUtils.isEmpty(str2)) {
            Log.w(str, a(str2, z));
        }
    }

    public static void w(String str, String str2, String str3) {
        if (!TextUtils.isEmpty(str2) || !TextUtils.isEmpty(str3)) {
            Log.w(str, a(str2, str3));
        }
    }

    public static void w(String str, String str2, String str3, Throwable th) {
        if (!TextUtils.isEmpty(str2) || !TextUtils.isEmpty(str3)) {
            Log.w(str, a(str2, str3), a(th));
        }
    }

    public static void w(String str, String str2) {
        if (!TextUtils.isEmpty(str2)) {
            Log.w(str, a(str2, false));
        }
    }

    public static void w(String str, String str2, Throwable th, boolean z) {
        if (!TextUtils.isEmpty(str2) || th != null) {
            Log.w(str, a(str2, z), a(th));
        }
    }

    public static void w(String str, String str2, Throwable th) {
        if (!TextUtils.isEmpty(str2) || th != null) {
            Log.w(str, a(str2, false), a(th));
        }
    }

    public static void e(String str, String str2, boolean z) {
        if (!TextUtils.isEmpty(str2)) {
            Log.e(str, a(str2, z));
        }
    }

    public static void e(String str, String str2, String str3) {
        if (!TextUtils.isEmpty(str2) || !TextUtils.isEmpty(str3)) {
            Log.e(str, a(str2, str3));
        }
    }

    public static void e(String str, String str2, String str3, Throwable th) {
        if (!TextUtils.isEmpty(str2) || !TextUtils.isEmpty(str3)) {
            Log.e(str, a(str2, str3), a(th));
        }
    }

    public static void e(String str, String str2) {
        if (!TextUtils.isEmpty(str2)) {
            Log.e(str, a(str2, false));
        }
    }

    public static void e(String str, String str2, Throwable th, boolean z) {
        if (!TextUtils.isEmpty(str2) || th != null) {
            Log.e(str, a(str2, z), a(th));
        }
    }

    public static void e(String str, String str2, Throwable th) {
        if (!TextUtils.isEmpty(str2) || th != null) {
            Log.e(str, a(str2, false), a(th));
        }
    }

    private static String a(String str) {
        int i = 1;
        if (TextUtils.isEmpty(str)) {
            return str;
        }
        int length = str.length();
        if (1 == length) {
            return String.valueOf(k);
        }
        StringBuilder stringBuilder = new StringBuilder(length);
        int i2 = 0;
        while (i2 < length) {
            char c;
            int i3;
            char charAt = str.charAt(i2);
            int i4;
            if (j.matcher(String.valueOf(charAt)).matches()) {
                if (i % 2 == 0) {
                    charAt = k;
                }
                i4 = i + 1;
                c = charAt;
                i3 = i4;
            } else {
                i4 = i;
                c = charAt;
                i3 = i4;
            }
            stringBuilder.append(c);
            i2++;
            i = i3;
        }
        return stringBuilder.toString();
    }

    private static Throwable a(Throwable th) {
        if (th == null) {
            return null;
        }
        Throwable aVar = new a(th);
        aVar.setStackTrace(th.getStackTrace());
        aVar.setMessage(b(th.getMessage()));
        Throwable cause = th.getCause();
        a aVar2 = aVar;
        while (cause != null) {
            Throwable aVar3 = new a(cause);
            aVar3.setStackTrace(cause.getStackTrace());
            aVar3.setMessage(b(cause.getMessage()));
            aVar2.b(aVar3);
            cause = cause.getCause();
            Throwable th2 = aVar3;
        }
        return aVar;
    }

    private static String b(String str) {
        if (TextUtils.isEmpty(str)) {
            return str;
        }
        char[] toCharArray = str.toCharArray();
        for (int i = 0; i < toCharArray.length; i++) {
            if (i % 2 == 0) {
                toCharArray[i] = k;
            }
        }
        return new String(toCharArray);
    }
}
